import requests
from bs4 import BeautifulSoup

url = "https://movie.douban.com/chart"
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
                  "Chrome/96.0.4664.110 Safari/537.36 "
}
html = requests.get(url, headers=headers)
html.encoding = "utf-8"

# BeautifulSoup
soup = BeautifulSoup(html.text, "lxml")
print("【%s】" % soup.select("title")[0].text.replace("\n", ""))
data = soup.select(".indent > div > table .item a > img")
for i, d in enumerate(data):
    print(d)
    img = requests.get(d.get('src'))
    with open("C:\\Users\\24\\Desktop\\豆瓣电影排行榜\\" + str(i+1) + '.' + d.get('alt') + '.jpg', 'wb') as f:
        f.write(img.content)
